<?

function rpc( $json_request ) {
    global $PARAPARA;

    $req_param = $json_request->param;

    if(!$req_param) {
        return new RPC_Error($json_request->operation, "PARAM", "No params");
    };

    $dbl = $PARAPARA->dblayer;

    $screenname = $req_param->login;
    $password   = $req_param->password;

    if( ($screenname == null) || !strlen($screenname))
        return new RPC_Error($json_request->operation, "PARAM", "Missing login parameter");
    if( ($password == null) || !strlen($password) )
        return new RPC_Error($json_request->operation, "PARAM", "Missing password parameter");

    $pwd_md5 = md5( $password );

    $account = $dbl->account_fetch_by_screenname( $screenname );

    if( !$account )
        return new RPC_Error($json_request->operation, "AUTH", "Authentication error");

    if( !$account->check_authentication( $screenname, $pwd_md5 ) )
        return new RPC_Error($json_request->operation, "AUTH", "Authentication error" );

    $rpc_retval = 
        array(
            'token'       => Token::generate($screenname, $pwd_md5, 3600 ),
            'screen_name' => $account->screen_name,
            'karma'       => $account->karma
            );

    return new RPC_Response( $json_request->operation, $rpc_retval );
}

return rpc( $json_request );

?>